﻿using Eoffice.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;

namespace Eoffice.Controllers
{
    public class EofficeController : Controller
    {
        EofficeDb db = new EofficeDb();

        public ActionResult Index()
        {
             return View();
           
        }
        #region[Login]
        public ActionResult Login()
        {

            return View();
        }
        #endregion
        #region[Login]
        [HttpPost]
        public ActionResult Login(FormCollection collect)
        {
            var Username = collect["Username"];
            var Password = collect["Password"];
            var list = db.NVs.Where(u => u.Username == Username && u.Password == Password).ToList();
            if (list.Count > 0)
            {
                FormsAuthentication.SetAuthCookie(Username, false);
                Session["Username"] = list[0].Username;
                return RedirectToAction("Index", "Eoffice");
            }
            else
            {
                ViewBag.Err = "Đăng nhập không thành công!";
                return View();
            }

        }
        #endregion
        #region[LogOut]
        [HttpGet]//phuong thuc get
        public ActionResult LogOff()
        {
            FormsAuthentication.SignOut();//xoa du lieu quyen va tai khoan
            return RedirectToAction("Index", "Eoffice");//nap lai trang home cho client
        }
        #endregion
    }
}
